package dingding.使用线程;

import java.util.ArrayList;
import java.util.List;

public class Demo3 {
    public static void main(String[] args) {

        long memory = Runtime.getRuntime().maxMemory();
        System.out.println(String.format("%d (%.2f M)", memory, (double) memory / (1024 * 1024)));

//        Thread mThreadTest = new Thread(() -> {
//            List<byte[]> list = new ArrayList<byte[]>();
//            while (true) {
//                System.out.println(new Date().toString() + Thread.currentThread() + "==");
//                byte[] b = new byte[1024 * 10240 * 1];
//                list.add(b);
//                try {
//                    Thread.sleep(3000);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//        mThreadTest.start();

        for (int i=0; i<5; i++){
            new Thread(new Runnable() {
                List<byte[]> list = new ArrayList<>();
                @Override
                public void run() {
                    while (true) {
                        list.add(new byte[1024 * 10240 * 1]);
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                        }
                        System.out.println("线程"+Thread.currentThread()+"添加完毕");
                    }

                }
            }).start();
        }
    }

}

